<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : !disabled ? '修改' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="金额" prop="finCostAmout">
        <el-input v-model="dataForm.finCostAmout" :disabled="disabled" placeholder="金额"></el-input>
      </el-form-item>
      <el-form-item label="支付类型" prop="finCostType">
        <!-- <el-input v-model="dataForm.finCostType" :disabled="disabled" placeholder="支付类型"></el-input> -->
        <el-select v-model="dataForm.finCostType">
          <el-option v-for="item in typeItem.typeList" :value="item.value" :key="item.value" name="finCostType">
            {{item.label}}
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付时间" prop="finCostTime">
        <!-- <el-input v-model="dataForm.finCostTime" :disabled="disabled" placeholder="支付时间"></el-input> -->
        <el-date-picker type="datetime" v-model="dataForm.finCostTime" placeholder="支付时间"></el-date-picker>
      
      </el-form-item>
      <el-form-item label="支付人" prop="finCosterName">
        <el-input v-model="dataForm.finCosterName" :disabled="disabled" placeholder="支付人姓名"></el-input>
      </el-form-item>
      <!-- <el-form-item label="支付人ID" prop="finCosterId">
        <el-input v-model="dataForm.finCosterId" :disabled="disabled" placeholder="支付人ID"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="1-" prop="finCostStatus">
        <el-input v-model="dataForm.finCostStatus" :disabled="disabled" placeholder="1-"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="创建人ID" prop="createUserId">
        <el-input v-model="dataForm.createUserId" :disabled="disabled" placeholder="创建人ID"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="修改人ID" prop="updateUserId">
        <el-input v-model="dataForm.updateUserId" :disabled="disabled" placeholder="修改人ID"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="修改时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" :disabled="disabled" placeholder="修改时间"></el-input>
      </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        disabled: false,
        visible: false,

        typeItem:{
          typeList:[
            {
              label:'交通费',
              value:1
            },{
              label:'住宿费',
              value:2
            },{
              label:'餐饮费',
              value:3
            },{
              label:'人工费',
              value:4
            },{
              label:'加盟费',
              value:5
            }
          ]
        },
        dataForm: {
          id: 0,
          finCostAmout: '',
          finCostType: '',
          finCostTime: '',
          finCosterName: '',
          finCosterId: '',
          finCostStatus: '',
          createUserId: '',
          updateUserId: '',
          updateTime: ''},
        dataRule: {
          name: [
            {required: true, message: '名称不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    methods: {
      init (id, disabled) {
        this.disabled = disabled
        this.dataForm.id = id || ''
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: `/fin/cost/info/${this.dataForm.id}`,
              method: 'get'
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm = data.cost
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm']
          .validate((valid) => {
            if (valid) {
              this.$http({
                url: `/fin/cost/${!this.dataForm.id ? 'save' : 'update'}`,
                method: 'post',
                data: this.dataForm
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500
                  })
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            }
          })
      }
    }
  }
</script>
